import { cloneDeep } from 'lodash'

/**
 * 重置状态
 * @param value
 * @param resetAfter
 */
export const useResetState = <T extends object>(value: T, resetAfter?: () => void) => {
  const state = reactive(cloneDeep(value)) as T & { [key: string]: unknown }
  const reset = () => {
    Object.keys(state).forEach((key) => delete state[key])
    Object.assign(state, cloneDeep(value))
    resetAfter && resetAfter()
  }
  return [state, reset] as const
}
